﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Configuration;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class TicketTemplateController : Controller
    {
        //
        // GET: /TicketTemplate/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var ticketTemplates = proxy.GetAllTicketTemplates();
            return View(ticketTemplates);
        }

        //
        // GET: /TicketTemplate/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var ticketTemplate = proxy.GetTicketTemplateById(id);
            return View(ticketTemplate);
        }

        //
        // GET: /TicketTemplate/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /TicketTemplate/Create

        [HttpPost]
        public ActionResult Create(TicketTemplate ticketTemplate)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreatTicketTemplate(ticketTemplate);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /TicketTemplate/Edit/5

        public ActionResult Edit(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var ticketTemplate = proxy.GetTicketTemplateById(id);
            return View(ticketTemplate);
        }

        //
        // POST: /TicketTemplate/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, TicketTemplate ticketTemplate)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateTicketTemplate(ticketTemplate);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /TicketTemplate/Delete/5

        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var ticketTemplate = proxy.GetTicketTemplateById(id);
            return View(ticketTemplate);
        }

        //
        // POST: /TicketTemplate/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, TicketTemplate ticketTemplate)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteTicketTemplateById(id);
            return RedirectToAction("Index");
        }
        //
        // GET: /TicketTemplate/Copy

        public ActionResult Copy(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var ticketTemplate = proxy.GetTicketTemplateById(id);
            return View("Edit",ticketTemplate);
        }

        //
        // POST: /TicketTemplate/Copy

        [HttpPost]
        public ActionResult Copy(TicketTemplate ticketTemplate)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                ticketTemplate.Id = -1;
                proxy.CreatTicketTemplate(ticketTemplate);
            }
            return RedirectToAction("Index");
        }
    }
}
